package controllers;

import play.*;
import play.data.validation.Required;
import play.modules.paginate.ValuePaginator;
import play.mvc.*;
import common.FBSecure;
import common.FBUtil;

import java.util.*;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import models.*;

@With(FBSecure.class)
public class Search extends FBController {
	
	public static void searchdriver(@Required String departurestate, @Required String arrivestate) {
    	setFbIdandName();

		User user = getUser();
		
		List<DriverJourney> searchDriverJourneys = DriverJourney.searchDriverJourney(departurestate, arrivestate);
		
		ValuePaginator paginator = new ValuePaginator(searchDriverJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchdriver.html", user, searchDriverJourneys, paginator);
    }
	
	public static void listalldriver() {
    	setFbIdandName();

		User user = getUser();
		
		List<DriverJourney> searchDriverJourneys = DriverJourney.orderDriverJourney();

		ValuePaginator paginator = new ValuePaginator(searchDriverJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchdriver.html", user, searchDriverJourneys, paginator);
    }
	
	public static void filterdriver(String departurestate, String departuretownn, String departurestreet, String arrivestate, String arrivetownn, String arrivestreet) {
    	setFbIdandName();

		User user = getUser();
		
		List<DriverJourney> searchDriverJourneys = DriverJourney.filterDriverJourney(departurestate, departuretownn, departurestreet, arrivestate, arrivetownn, arrivestreet);
		
		ValuePaginator paginator = new ValuePaginator(searchDriverJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchdriver.html", user, searchDriverJourneys, paginator);
    }
	
	
    
    public static void searchhitchhiker(@Required String departurestate, @Required String arrivestate) {
    	setFbIdandName();

		User user = getUser();

		List<HitchhikerJourney> searchHitchhikerJourneys = HitchhikerJourney.searchHitchhikerJourney(departurestate, arrivestate);
		
		ValuePaginator paginator = new ValuePaginator(searchHitchhikerJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchhitchhiker.html", user, searchHitchhikerJourneys, paginator);
    }
    
    public static void listallhitchhiker() {
    	setFbIdandName();

		User user = getUser();

		List<HitchhikerJourney> searchHitchhikerJourneys = HitchhikerJourney.orderHitchhikerJourney();
		
		ValuePaginator paginator = new ValuePaginator(searchHitchhikerJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchhitchhiker.html", user, searchHitchhikerJourneys, paginator);
    }	
    
	public static void filterhitchhiker(String departurestate, String departuretownn, String departurestreet, String arrivestate, String arrivetownn, String arrivestreet) {
    	setFbIdandName();
    	
		User user = getUser();
		
		List<HitchhikerJourney> searchHitchhikerJourneys = HitchhikerJourney.filterHitchhikerJourney(departurestate, departuretownn, departurestreet, arrivestate, arrivetownn, arrivestreet);
		
		ValuePaginator paginator = new ValuePaginator(searchHitchhikerJourneys);
		paginator.setPageSize(5);
		
		renderTemplate("Search/searchhitchhiker.html", user, searchHitchhikerJourneys, paginator);
    }
    
}
